package br.unifor.cct.mia.dataenhancement;

import java.awt.Point;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class Structure {

	private String strucFile;
	private Map map = new LinkedHashMap();
	
	public void addElement(Attribute attribute, List values) {
		map.put(attribute, values);
	}
	
	public Attribute getAttribute(int pos) {
		return (Attribute)map.keySet().toArray()[pos];
	}

	public List getValues(int pos) {
		return (List)map.values().toArray()[pos];
	}	
	
	public List getValues(Attribute attribute) {
		return (List)map.get(attribute);
	}
	
	public int size() {
		return map.size();
	}
	
	public String[] getStringValues(List positions, double[] array) {
		String[] values = new String[array.length];
		
		Point pt;
		Attribute att;
		
		for (int i = 0; i < array.length; i++) {
			pt = (Point)positions.get(i);
			att = getAttribute(pt.y); 
			
			if (att.getTipo().equalsIgnoreCase(Attribute.CONTINUOUS))
				if (att.isInteger()) values[i] = Integer.toString((int)array[i]);
				else values[i] = Double.toString(array[i]);
			else {				
				try {
					values[i] = (String)getValues(pt.y).get((int)array[i]);
				}
				catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		
		return values;
	}
	
	public String[] getStringValues(List positions, String[] array) {
		String[] values = new String[array.length];
		
		Point pt;
		Attribute att;
		
		for (int i = 0; i < array.length; i++) {
			pt = (Point)positions.get(i);
			att = getAttribute(pt.y); 
			
			if (att.getTipo().equalsIgnoreCase(Attribute.CONTINUOUS))
				if (att.isInteger() ) { 
					values[i] = Integer.toString( Integer.parseInt(array[i]) );
				}
				else {
					values[i] = array[i];
				}
			else {	
				values[i] = array[i];
			}
		}
		
		return values;
	}

	public String getStrucFile() {
		return strucFile;
	}

	public void setStrucFile(String strucFile) {
		this.strucFile = strucFile;
	}	
	
}
